import fs from 'fs/promises'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'node:url'

import minimist from 'minimist'

const __dirname = dirname(fileURLToPath(import.meta.url))

// 命令行参数
const argv = minimist(process.argv.slice(2), {
  default: {
    env: process.env.NODE_ENV || 'production',
  },
})

export const isDev = argv.env === 'development' || argv.env === 'dev'
export const rootDir = resolve(__dirname, '..')
export const env = argv.env
export const dataDir = resolve(rootDir, 'data')
export const translateDir = resolve(dataDir, 'translate')

export const techniqueDir = resolve(dataDir, 'technique')
export const subTechniqueDir = resolve(dataDir, 'sub-technique')
export const domain = 'https://attack.mitre.org'

// 确保目录存在
fs.mkdir(techniqueDir, { recursive: true })
fs.mkdir(subTechniqueDir, { recursive: true })

fs.mkdir(resolve(translateDir, 'technique'), { recursive: true })
fs.mkdir(resolve(translateDir, 'sub-technique'), { recursive: true })

export default {
  ...argv,
  isDev,
  rootDir,
  dataDir,
  techniqueDir,
  translateDir,
  subTechniqueDir,
}
